package sz.szsmk.citizencard.ui.adapter;

import android.content.Context;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.ArrayList;

import sz.szsmk.citizencard.R;
import sz.szsmk.citizencard.model.network.bean.response.QueryCitizenCardRes;
import sz.szsmk.citizencard.ui.activity.MyCityCardActivity;

/**
 * Copyright (c)2018
 * author: zdh
 * created on: 2018/12/27 16:15
 * description:
 */
public class MycitycardAdapter extends RecyclerView.Adapter<MycitycardAdapter.MycitycardHolder> {
    private Context mContext;
    private ArrayList<ArrayList<QueryCitizenCardRes.CitizenCardInfoListBean>> viewData;
    private int type;
    private AppCardAdapter appCardAdapter;

    public MycitycardAdapter(MyCityCardActivity myCityCardActivity) {
        mContext = myCityCardActivity;
    }

    @Override
    public MycitycardHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.mycitycard_view, parent, false);
        return new MycitycardHolder(view);
    }

    @Override
    public void onBindViewHolder(MycitycardHolder holder, int position) {
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mContext);
        holder.mCityRv.setLayoutManager(linearLayoutManager);
        appCardAdapter = new AppCardAdapter(mContext);
        holder.mCityRv.setAdapter(appCardAdapter);
        if (viewData != null) {

            if (type == 0) {
                if (position == 1) {
                    holder.title1.setText("我的市民卡");
                    holder.title2.setText("(绑定的市民卡)");
                }
                if (position == 0) {
                    holder.title1.setText("我的市民卡");
                    holder.title2.setText("(实名认证身份的市民卡)");
                }
            }

            if (type == 1) {
                holder.title1.setText("我的市民卡");
                holder.title2.setText("(实名认证身份的市民卡)");
            }
            if (type == 2) {
                holder.title1.setText("我的市民卡");
                holder.title2.setText("(绑定的市民卡)");
            }

            appCardAdapter.setViewData(viewData.get(position));
            appCardAdapter.notifyDataSetChanged();

        }
    }

    @Override
    public int getItemCount() {
        return viewData == null ? 0 : viewData.size();
    }

    public void setViewData(ArrayList<ArrayList<QueryCitizenCardRes.CitizenCardInfoListBean>> viewData, int i) {
        this.viewData = viewData;
        type = i;
    }

    public static class MycitycardHolder extends RecyclerView.ViewHolder {

        private final RecyclerView mCityRv;
        private final TextView title1;
        private final TextView title2;

        public MycitycardHolder(View itemView) {
            super(itemView);
            mCityRv = (RecyclerView) itemView.findViewById(R.id.mycitycard_card_rv);
            title1 = (TextView) itemView.findViewById(R.id.mycitycard_title1);
            title2 = (TextView) itemView.findViewById(R.id.mycitycard_title2);
        }
    }

}
